package com.smartwasser.yunhtgl.apphtgl.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.smartwasser.yunhtgl.apphtgl.R;
import com.smartwasser.yunhtgl.apphtgl.bean.CaseProcess2Bean.ListBean;

import java.util.List;

import static com.smartwasser.yunhtgl.apphtgl.R.id.checkbox_case_layout;

public class CaseAdapter02 extends BaseAdapter {
    private Context context;
    private List<ListBean> data;

    public CaseAdapter02(Context context, List<ListBean> list) {
        this.context = context;
        this.data = list;
    }

    public void refresh(List<ListBean> list) {
        this.data = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (null != data && data.size() > 0) {
            return data.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolders holders;
        if (convertView == null) {
            holders = new ViewHolders();
            convertView = View.inflate(context, R.layout.case_item1, null);
            holders.checkbox_case_layout = convertView.findViewById(checkbox_case_layout);
            holders.sp_item_name = convertView.findViewById(R.id.sp_item_name);
            holders.sp_item_bd = convertView.findViewById(R.id.sp_item_bd);
            holders.sp_item_money = convertView.findViewById(R.id.sp_item_money);
            holders.sp_item_id = convertView.findViewById(R.id.sp_item_id);
            holders.sp_item_type = convertView.findViewById(R.id.sp_item_type);
            convertView.setTag(holders);
        } else {
            holders = (ViewHolders) convertView.getTag();
        }
        if (null != data && data.size() > 0) {
            holders.sp_item_name.setText(data.get(position).getName().toString());
            holders.sp_item_bd.setText("标的 : " + data.get(position).getContractObject());
            holders.sp_item_money.setText("金额 : " + data.get(position).getContractValue());
            holders.sp_item_id.setText("编号 : " + data.get(position).getCode());
            holders.sp_item_type.setText("类型 : " + data.get(position).getType());
        }
        return convertView;
    }

    class ViewHolders {
        public LinearLayout checkbox_case_layout;
        public TextView sp_item_name;
        public TextView sp_item_bd;
        public TextView sp_item_money;
        public TextView sp_item_id;
        public TextView sp_item_type;
    }
}